package com.it.ems.service.impl;

import com.it.ems.entity.UserRole;
import com.it.ems.mapper.UserRoleMapper;
import com.it.ems.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserRoleServiceImpl implements UserRoleService {
    
    @Autowired
    private UserRoleMapper userRoleMapper;
    
    @Override
    public List<UserRole> findByUserId(Long userId) {
        return userRoleMapper.findByUserId(userId);
    }
    
    @Override
    public List<UserRole> findByRoleId(Long roleId) {
        return userRoleMapper.findByRoleId(roleId);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(UserRole userRole) {
        return userRoleMapper.insert(userRole) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(Long id) {
        return userRoleMapper.delete(id) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByUserId(Long userId) {
        return userRoleMapper.deleteByUserId(userId) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByRoleId(Long roleId) {
        return userRoleMapper.deleteByRoleId(roleId) > 0;
    }
} 